/**
 * Copyright By Grandsoft Company Limited.  
 * 2013-6-13 上午11:30:05
 */
package com.glodon.ggzy.jypt.controller;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.glodon.ggzy.core.model.Page;
import com.glodon.ggzy.core.utils.JsonUtils;
import com.glodon.ggzy.core.utils.PageSearchModel;
import com.glodon.ggzy.core.utils.QuerySupport;
import com.glodon.ggzy.entity.GgTdJy;
import com.glodon.ggzy.fwpt.service.IJsgcProjectService;
import com.glodon.ggzy.fwpt.service.ITdfcProjectService;

/**
 * 
 * 竟买人处理控制类
 * @author yangjf
 * @since jdk1.6
 * @date 2013-6-13
 *  
 */

@Controller
public class JmrController {

	protected Logger logger = LoggerFactory.getLogger(getClass());

	@Autowired
	private IJsgcProjectService jsgcProjectService;

	/**
	 * 
	 * 竟买人-主页
	 * @param model
	 * @return
	 */
	@RequestMapping("/jypt/jmr_index")
	public String jmrIndex(Model model) {
		return "/jypt/jmr_index";
	}

	/**
	 * 
	 * 竟买人-交易方式
	 * @param model
	 * @return
	 */
	@RequestMapping("/jypt/jmr_jyfs")
	public String jmrJyfs(Model model) {
		return "/jypt/jmr_jyfs";
	}

	/**
	 * 
	 * 我的项目
	 * @param model
	 * @return
	 */
	@RequestMapping("/jypt/jmr_my_project")
	public String myProject(Model model) {
		return "/jypt/jmr_my_project";
	}

	/**
	 * 竟买人-交易信息
	 * @param model
	 * @return
	 */
	@RequestMapping("/jypt/jmr_jyxx")
	public String jmrJyxx(Model model) {
		return "/jypt/jmr_jyxx";
	}

	@Autowired
	private ITdfcProjectService tdfcProjectService;

	@RequestMapping("/jypt/load_jmr_jyxx_data")
	public void loadJmrJyxxData(Model model,String gpNo, int rows, int page, HttpServletRequest request, HttpServletResponse response) {
		
		String gsname = "";
		if (StringUtils.isNotEmpty(gpNo)) {
			try {
				gsname = "%" + URLDecoder.decode(gpNo, "UTF-8") + "%";
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
				gsname = "";
			}
		}
		
		PageSearchModel psm = new PageSearchModel();
		
		psm.setPageNo(page);
		psm.setPageSize(rows);
		psm.setSession(request.getSession());
		psm.addParamToMap(QuerySupport.QUERYCLASS, GgTdJy.class);
		psm.addParamToMap("zzjgNo",psm.getOrgCode());
		psm.addParamToMap("gpNo",gsname);
		Page queryPage = tdfcProjectService.queryCrrJyxxTdfcPage(psm);
		String jsonStr = "";
		try {
			jsonStr = JsonUtils.toJsonStr(queryPage);
			response.getWriter().write(jsonStr);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
